package com.course.servlet;

import com.course.entity.Teacher;
import com.course.service.TeacherService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/addTeacher")
public class AddTeacherServlet extends HttpServlet {
    private final TeacherService teacherService = new TeacherService();

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) 
            throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");

        String teacherNumber = request.getParameter("teacherNumber");
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        String name = request.getParameter("name");
        String gender = request.getParameter("gender");
        String department = request.getParameter("department");
        String email = request.getParameter("email");
        String phone = request.getParameter("phone");

        Teacher teacher = new Teacher();
        teacher.setTeacherNumber(teacherNumber);
        teacher.setUsername(username);
        teacher.setPassword(password);
        teacher.setName(name);
        teacher.setGender(gender);
        teacher.setDepartment(department);
        teacher.setEmail(email);
        teacher.setPhone(phone);

        teacherService.addTeacher(teacher);

        response.sendRedirect("guanliyuan_teacher_manage");
    }
} 